package com.mapper;

import com.bean.Clazz;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ClazzMapperByAnnotation {

    @Select("select * from t_clazz")
    public List<Clazz> selectAllClazz();

    @Insert("insert into t_clazz (cname) values (#{cname})")
    public int addClazz(Clazz clazz);

    @Update("update t_clazz set cname = #{cname} where id=#{id}")
    public int modifyClazz(Clazz clazz);

    @Delete("delete from t_clazz where id=#{id}")
    public int delClazz(int id);

    @Select("select * from t_clazz where id=#{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "cname",property = "cname"),
            @Result(column = "id",property = "students",
                    many = @Many(select ="com.mapper.StudentMapperByAnnotation.findStuByClassid" ))
    })
    public Clazz findStuForClazzByid(int id);

    @Select("select * from t_clazz where id=#{id}")
    public Clazz findClazzById(int id);
}
